Skip to content

Comments

Crash fix in case of forks: use static TLS for alloc tracking storage#490

Merged
r1viollet merged 3 commits intomainfrom
r1viollet/tls-initial-exec-cleanup
Feb 24, 2026
Merged

Crash fix in case of forks: use static TLS for alloc tracking storage#490
r1viollet merged 3 commits intomainfrom
r1viollet/tls-initial-exec-cleanup

Conversation

@r1viollet
Copy link
Collaborator

What does this PR do?

Replacement of PR #483 to remove pthread APIs to manage TLS.
This is an idea from @nsavoire in following PR

Motivation

A user reported a crash in case of forks.
Although we do not understand the sequence that lead to calling init inside the child, with this PR we remove the risk as the storage will always be available through static TLS

Additional Notes

NA

How to test the change?

The PR includes a test for forks.
I did not use gtest as it was not safe with forks.

nsavoire and others added 2 commits February 5, 2026 00:43
initial-exec __thread and placement new.

- Add `initialized` field to TrackerThreadLocalState
- Shared C header (tls_state_storage.h) for size/alignment
  constants between loader.c and C++ code, with static_assert
- Clean up dead code: _key_once, _tl_state_key, delete_tl_state
- Add standalone fork test validating TLS zero-init, fork
  inheritance, and fresh-thread behavior
@r1viollet r1viollet force-pushed the r1viollet/tls-initial-exec-cleanup branch from 67204b8 to 7fd9a0d Compare February 22, 2026 17:28
@r1viollet r1viollet changed the title Crash fix in case of forks: use static TLS for alloc structure Crash fix in case of forks: use static TLS for alloc tracking storage Feb 22, 2026
@pr-commenter
Copy link

pr-commenter bot commented Feb 22, 2026

Benchmark results for collatz

Parameters

Baseline Candidate
config baseline candidate
profiler-version ddprof 0.23.0+820196ba.96300814 ddprof 0.23.0+b5615391.98307349

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean execution_time
scenario:ddprof -S bench-collatz --preset cpu_only collatz_runner.sh same

@pr-commenter
Copy link

pr-commenter bot commented Feb 22, 2026

Benchmark results for BadBoggleSolver_run

Parameters

Baseline Candidate
config baseline candidate
profiler-version ddprof 0.23.0+820196ba.96300814 ddprof 0.23.0+b5615391.98307349

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean execution_time
scenario:ddprof -S bench-bad-boggle-solver BadBoggleSolver_run work 1000 same

@r1viollet r1viollet marked this pull request as ready for review February 24, 2026 08:49
@r1viollet r1viollet requested a review from nsavoire as a code owner February 24, 2026 08:49
// (C++). Correctness enforced at compile time via static_assert in
// allocation_tracker.cc.
#ifdef __cplusplus
enum : unsigned char {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is slightly weird, but it has to be C compatible and linters were annoying, I initially just had a #define

Copy link
Collaborator

@nsavoire nsavoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work !

@r1viollet r1viollet merged commit 6791e0c into main Feb 24, 2026
3 checks passed
@r1viollet r1viollet deleted the r1viollet/tls-initial-exec-cleanup branch February 24, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants